﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ext.Net;
using Enterprise.Web;
namespace Viewer.Base
{
    public partial class LBase :  BusinessPage
    {
        public override void AddEvent()
        {
            UCAddToChucHanhChinh1.ShowDialog("AddNew", 0);

        }

        protected void Page_Load(object sender, EventArgs e)
        {
            
            //UCSimpleListBase.SetDataSource(ds);
        }


        public override void InitializeControls()
        {
            PnSearch.Height = 70;
            //UCSimpleListBase.GridID = (int)Config.ViewerConstant.GridList.GRIDID_LBASE;
            UCSimpleListBase.SetRowCommandWithUser("a");

            UCSimpleListBase.AddGridColumn("TenToChucShort", "Tên Tổ Chức (Short)",  200);
            UCSimpleListBase.AddGridColumn("TenToChucFull", "Tên Tổ Chức Full",200);
            UCSimpleListBase.AddGridColumn("GhiChu", "Ghi Chú",200);
            //UCSimpleListBase.AddGridColumn("StringField", "String", 100);
            //UCSimpleListBase.AddGridColumn("IntField", "Int", 200);
            //UCSimpleListBase.AddGridColumn("Timestamp", "Timestamp");
            //UCSimpleListBase.AddGridDateColumn("Today", "Today", "dd/MM/yyyy");
            UCSimpleListBase.SetAutoExpandColumn("TenToChucShort");
            UCSimpleListBase.SetPageSize(24);

            //UCSimpleListBase.ReconfigureGrid();
        }

        public override void LoadData()
        {
            Viewer.BusinessObject.BusinessEntities.CommonCode common = new Viewer.BusinessObject.BusinessEntities.CommonCode();
            //Load xếp hạng
            storeXepHang.DataSource = common.LoadDataCommonByCodeKey(common.XepHangDonVi);
            storeXepHang.DataBind();
            //Load Khoi
            storeKhoi.DataSource = common.LoadDataCommonByCodeKey(common.KhoiQuanlyToChuc);
            storeKhoi.DataBind();
            //Loai To Chuc
            storeLoaiToChuc.DataSource = common.LoadDataCommonByCodeKey(common.LoaiToChuc);
            storeLoaiToChuc.DataBind();
        }

        protected void btnSearch_Click(object sender, DirectEventArgs e)
        {
            this.Search();
        }

        //public override void ShowDetail(int id)
        //{
        //    UCSimpleDetailBase1.ShowDialog(id);
        //}

        public override void Search()
        {
            string strWhere = string.Empty;
            if (this.cboXepHang.SelectedIndex != -1)
            {
                if (strWhere.Length > 0) 
                {
                    strWhere += " AND ";
                }
                strWhere += string.Format("XepHangDonViID={0}",this.cboXepHang.SelectedItem.Value);
            }

            if (this.cboKhoi.SelectedIndex != -1)
            {
                if (strWhere.Length > 0)
                {
                    strWhere += " AND ";
                }
                strWhere += string.Format("KhoiQuanLyID = {0}", this.cboKhoi.SelectedItem.Value);
            }

            if (this.cboLoaiToChuc.SelectedIndex != -1)
            {
                if (strWhere.Length > 0)
                {
                    strWhere += " AND ";
                }
                strWhere += string.Format("LoaiToChucID = {0}", this.cboLoaiToChuc.SelectedItem.Value);
            }

            if (!string.IsNullOrEmpty(this.txtTenToChuc.Text.Trim()))
            {
                if (strWhere.Length > 0)
                {
                    strWhere += " AND ";
                }
                strWhere += string.Format("TenToChucShort.Contains(\"{0}\")", this.txtTenToChuc.Text.Trim());
            }

            Viewer.BusinessObject.BusinessEntities.NSToChuc tochucs = new Viewer.BusinessObject.BusinessEntities.NSToChuc();
            List<Viewer.BusinessObject.BusinessEntities.NSToChuc> nsToChucs = tochucs.Search(strWhere);
            UCSimpleListBase.SetDataSource(nsToChucs);
        }

    }
}